import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Jiang Jinxi
 * Date: 2024-04-13
 * Time: 20:32
 */
public class Test2 {
    public static int[] findLargestBlock(int[][] m){
        int[] arr = new int[3];
        int size = m.length;
        while(size > 0){
        for (int i = 0; i <= m.length-size; i++) {
            for (int j = 0; j <= m[i].length-size; j++) {
                if(m[i][j] == 1){
                        int sum = 0;
                        for (int k = i; k - i < size; k++) {
                            for (int l = j; l - j< size; l++) {
                                sum += m[k][l];
                            }
                        }
                        if(sum == size*size){
                            arr[0] = i;
                            arr[1] = j;
                            arr[2] = size;
                            return arr;
                        }

                    }

                }
            }
            size--;
        }
        return arr;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the number of rows in the matrix:");
        int x = scanner.nextInt();
        int[][] arr = new int[x][x];
        System.out.println("Enter the matrix row by row:");
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < x; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        int[] m = findLargestBlock(arr);
        System.out.println("The maximum square submatrix is at ("+m[0]+","+m[1]+") with size "+m[2]);


    }
}
